package com.lanxin.oa.personnel.controller;
import com.lanxin.bean.ZzAdjustment;
import com.lanxin.bean.ZzEmployee;
import com.lanxin.oa.personnel.service.AdjustDaoService;
import com.lanxin.util.PageBean;
import com.lanxin.util.TimeConverter;
import com.lanxin.util.ZzEmp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.Date;

@Controller
@RequestMapping("/adjust")
public class AdjustController extends TimeConverter {

    @Autowired
    private AdjustDaoService adjustDaoService;

    @RequestMapping("/findEmpSimpleInfo")
    @ResponseBody
    public ZzEmp findEmpSimpleInfo(Integer oid) {
        ZzEmployee employee = adjustDaoService.selectEmpById(oid);
        ZzEmp emp=new ZzEmp();
        emp.setOid(employee.getOid());
        emp.setEmpname(employee.getEmpName());
        emp.setStartdeptid(employee.getDept().getOid());
        emp.setStartdeptname(employee.getDept().getDeptName());
        emp.setStartjobid(employee.getBasic().getOid());
        emp.setStartjobname(employee.getBasic().getName());
        return emp;
    }

    @RequestMapping("/addAdjustment")
    @ResponseBody
    public boolean addAdjustment(ZzAdjustment zzAdjustment) {
        return adjustDaoService.insertAdjust(zzAdjustment);

    }

    @RequestMapping("/adjustmentInfo")
    public ModelAndView adjustmentInfo(Integer page, Integer pageSize, Integer empid, Date startDate,Date endDate){
        PageBean<ZzAdjustment> pageBean = adjustDaoService.getAdjustPage(page, pageSize, empid,startDate,endDate);
        ModelAndView mv=new ModelAndView();
        mv.addObject("pageBean",pageBean);
        mv.addObject("empid",empid);
        mv.addObject("startDate",startDate);
        mv.addObject("endDate",endDate);
        mv.setViewName("../view/personnel/adjustmentinfo.jsp");
        return mv;
    }

}
